package ssm.blog.service.impl;

import org.springframework.stereotype.Service;
import ssm.blog.dao.BlogTypeMapper;
import ssm.blog.entity.BlogType;
import ssm.blog.entity.BlogTypeExample;
import ssm.blog.service.BlogTypeService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: lyon
 * @description: 博客分类-服务层
 * @author: Lyon
 * @create: 2018-05-13 22:50
 **/
@Service
public class BlogTypeServiceImpl implements BlogTypeService {
    @Resource
    BlogTypeMapper mapper;
    @Override
    public int addBlogType(BlogType blogType) {
        blogType.setBlog_count(0);
        return mapper.insert(blogType);
    }

    @Override
    public List<BlogType> list() {
        BlogTypeExample example=new BlogTypeExample();
        example.setOrderByClause("id desc");
        return mapper.selectByExample(example);
    }

    @Override
    public List<BlogType> listByKeyword(String keyword) {
        BlogTypeExample example=new BlogTypeExample();
        example.setOrderByClause("id desc");
        example.createCriteria().andType_nameLike("%"+keyword+"%");
        return mapper.selectByExample(example);
    }

    @Override
    public int dele(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }
    @Override
    public int deles(List<Integer> IDS){
        BlogTypeExample example=new BlogTypeExample();
        example.createCriteria().andIdIn(IDS);
        return mapper.deleteByExample(example);
    }

    @Override
    public BlogType selectById(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByIdSelective(BlogType blogType) {
        return mapper.updateByPrimaryKeySelective(blogType);

    }

    @Override
    public int count() {
        BlogTypeExample example=new BlogTypeExample();
        return mapper.countByExample(example);
    }
}
